package com.hhu.wangzb.common.entity.filter;

import java.util.Map;

public class RenameFilter implements Filter {

    // 优先级，数字越大越优先执行
    private final int priority = 0;

    @Override
    public Map<String, Object> doFilter(Map<String, Object> entityMap, FilterEntity filterEntity) {

        Map<String, String> renameMap = filterEntity.getRename();

        if (renameMap == null || renameMap.size() == 0) return entityMap;

        for (String oldName : renameMap.keySet()) {
            if (entityMap.containsKey(oldName)) {
                entityMap.put(renameMap.get(oldName), entityMap.get(oldName));
                entityMap.remove(oldName);
            }
        }

        return entityMap;
    }

    @Override
    public int getPriority() {
        return priority;
    }
}
